const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
    /**
     * 页面的初始数据
     */
    data: {
      avatarUrl: defaultAvatarUrl,
      nickname: '微信用户'
    },
    
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
       //从后端数据库获取用户信息
    const openid=wx.getStorageSync('openid');
   console.log(openid)
   if(!openid){
     wx.navigateTo({
       url: '../index/index',
     })
   }
    const that=this;
    wx.request({
      url: 'http://localhost:3000/user/info',
      method: 'GET',
      data: {
        openid: openid
      },
      success(res) {
        if (res.data.code === 0) {
          const userInfo=res.data.userInfo;
          that.setData({
            avatarUrl: userInfo.avatar ,
            nickname: userInfo.nickname ,
          })
        } else {
          wx.showToast({
            title: '获取信息失败,未登录，请重新登录',
            icon: 'none',
            duration: 2000
          })
        }
      },
      fail() {
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000
        })
      }
    })
    },

    orderpage:function(){
        wx.navigateTo({
          url: '../uploaded/uploaded',
        })
      },
      
    personalpage:function(){
        wx.navigateTo({
          url: '../personal/personal',
        })
      },
      
    servicepage:function(){
        wx.navigateTo({
          url: '../feedback/feedback',
        })
      },
      
    settingpage:function(){
        wx.navigateTo({
          url: '../settings/settings',
        })
      },
      
    starpage:function(){
        wx.navigateTo({
          url: '../star/star',
        })
      },
      
    commentpage:function(){
        wx.navigateTo({
          url: '../comment/comment',
        })
      },
})
